package com.kkui.liuxin.controller;



import com.kkui.liuxin.service.MkdirService;
import com.kkui.liuxin.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;

/**
 *
 * @author kkui
 */

@Slf4j
@Controller
@RequestMapping("/api")
public class FileManage {
    @Resource
    UserService userService;
    @Resource
    MkdirService mkdirService;


    /**
     * 目录文件列表
     * @return 返回json格式文件列表
     */
    @ResponseBody
    @PostMapping("/list")
    public String getFileList(@RequestParam("path") String path,@RequestHeader("Authorization") String authorization,HttpServletResponse response){

        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");

        int userId = userService.jwtGetUserId(authorization);
        String sonPath = userId + File.separator + path.replace("/",File.separator) + File.separator;
        String json = mkdirService.listMkdir(sonPath);

        return json;
    }




}
